package org.xjtu.weteam.model.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@Entity
@Table(name = "message")
public class Info {
    @Id
    @TableId(value = "id",type = IdType.AUTO)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    @Column(name = "user_id")
    private Integer userId;
    @Column(name="content")
    private String note;
    @Column(name = "date")
    private Timestamp date;
    @Column(name = "is_read")
    private Boolean isRead;
    @Column(name = "title")
    private String title;
    @Column(name = "is_deleted")
    @TableLogic
    private Boolean isDeleted;
    public String getFormattedDate() {
        if (date == null) {
            return null;
        }
        // 创建一个DateTimeFormatter来定义日期时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 将Timestamp转换为LocalDateTime
        LocalDateTime localDateTime = date.toLocalDateTime();
        // 格式化LocalDateTime
        return localDateTime.format(formatter);
    }
}

